﻿using System;
using System.Collections.Generic;
using System.Collections;
using NetWork;
using ProtoBuf.Message;
using UnityEngine;

namespace Room
{
    class RoomNetUnion : RoomNetBase
    {
        private RoomUnion roomUnion
        {
            get { return roomBase as RoomUnion; }
        }
        public override void Enter()
        {
            base.Enter();

        }
        public override void Leave()
        {
            base.Leave();
        }

        public override void Tick()
        {
            base.Tick();
        }

        public override void RegistSocketHandler()
        {
            base.RegistSocketHandler();
            //红名信息
            NetAPI.RegistSocketHandler(OpDefine.SCFieldPlayerState, SCFieldPlayerState);
            NetAPI.RegistSocketHandler(OpDefine.SCUnionBuilding, SCUnionBuilding);
        }

        public override void UnRegistSocketHandler()
        {
            base.UnRegistSocketHandler();
            //红名信息
            NetAPI.UnregisterSocketHandler(OpDefine.SCFieldPlayerState, SCFieldPlayerState);
            NetAPI.UnregisterSocketHandler(OpDefine.SCUnionBuilding, SCUnionBuilding);
        }

        #region SC消息
        public void SCFieldPlayerState(object obj)
        {
            SCFieldPlayerState msg = (SCFieldPlayerState)obj;
            foreach (var side in msg.player)
            {
                playerSideQueue.Enqueue(side);
            }
        }

        protected override void SCCurrentPosition(object obj)
        {
            base.SCCurrentPosition(obj);
            var charactor = roomBase.charactorManager.GetSelfCharactor();
#if UNITY_EDITOR
           // charactor.transform.localPosition = new Vector3(0, 3, 0);
#endif
            roomUnion.smallMap.miniMapComponent.SetMajorCharactor(charactor.transform);
            roomUnion.RoomLoadEnd();
        }

        void SCUnionBuilding(object obj)
        {
            SCUnionBuilding building = (SCUnionBuilding)obj;
            StaticData.treeOpen = building.guardTreeOpen == BOOL.TRUE;
            StaticData.heroOpen = building.heroStatueOpen == BOOL.TRUE;

            var room = roomBase as RoomUnion;
            room.SetGuardTree(StaticData.treeOpen);
            room.SetHeroStatue(StaticData.heroOpen);
        }

        #endregion

        public override void SendCSCurrentPosition(object sender)
        {
            CSCurrentPosition msg = new CSCurrentPosition();
            msg.showArround = 1;//显示周围玩家
            NetAPI.SendSocket(OpDefine.CSCurrentPosition, msg);
            //聊天信息
            NetAPI.SendSocket(OpDefine.CSSceneChatCache, new CSSceneChatCache());
        }
    }
}
